/**
 * @filename:SysLogController 2022年1月27日
 * @project Wonder xhadmin Framework  V1.0
 * Copyright(c) 2020 LuZhongren Co. Ltd. 
 * All right reserved. 
 */
package com.wonder.admin.controller;


import com.wonder.admin.domain.SysLog;
import com.wonder.admin.service.SysLogService;
import com.wonder.admin.request.SysLogRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wonder.common.common.AjaxResult;
import com.wonder.common.common.CommonPage;
import com.wonder.common.utils.MessageUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
/**   
 * 
 * <p>说明： 操作日志管理API接口层</P>
 * @version: V1.0
 * @author: LuZhongren
 * @time    2022年1月27日
 *
 */
@Api(tags = "操作日志管理")
@RestController
@RequestMapping("/log")
public class SysLogController {
	
	@Autowired
	private SysLogService sysLogService;
	
	@ApiOperation(value = "操作日志管理列表")
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public AjaxResult<CommonPage<SysLog>> index(SysLogRequest sysLogRequest) {
	
		Page<SysLog> page = new Page<SysLog>(sysLogRequest.getPageNum(), sysLogRequest.getPageSize());
		IPage<SysLog> list = sysLogService.selectList(sysLogRequest, page);
		return AjaxResult.success(CommonPage.restPage(list));
	}
	
	/**
	 * @explain 查询对象  <swagger GET请求>
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@GetMapping("/getById/{id}")
	@ApiOperation(value = "获取操作日志管理对象", notes = "作者：LuZhongren")
	@ApiImplicitParam(paramType="path", name = "id", value = "对象id", required = true,dataTypeClass = Long.class, dataType = "Long")
	public AjaxResult<SysLog> getById(@PathVariable("id")Long id){
		SysLog sysLog=sysLogService.getById(id);
		if (null!=sysLog ) {
			 return AjaxResult.success(sysLog);
		}else {
			 return AjaxResult.failed(MessageUtils.message("search.not.exist"));
		}
		
	}
	
	/**
	 * @explain 删除对象
	 * @param   对象参数：id
	 * @return  JsonResult
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/deleteById")
	@ApiOperation(value = "删除", notes = "作者：LuZhongren")
	@ApiImplicitParam(paramType="query", name = "id", value = "对象id", required = true,dataTypeClass = Long.class, dataType = "Long")
	public AjaxResult<SysLog> deleteById(Long id){
		
		SysLog sysLog=sysLogService.getById(id);
		if (null!=sysLog) {
		  boolean rsg = sysLogService.removeById(id);
		  if (rsg) {
			    return AjaxResult.success(MessageUtils.message("delete.success"));
		  }else {
			   return AjaxResult.failed(MessageUtils.message("delete.fail"));
		  }
		}else {
			 return AjaxResult.failed(MessageUtils.message("delete.not.exist"));
		}
	}
	
	/**
	 * @explain 添加
	 * @param   对象参数：SysLog
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/insert")
	@ApiOperation(value = "添加", notes = "作者：LuZhongren")
	public AjaxResult<SysLog> insert(SysLog entity){

		if (null!=entity) {
			boolean rsg = sysLogService.save(entity);
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("insert.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("insert.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("insert.parameter.error"));
		}
	}
	
	/**
	 * @explain 修改
	 * @param   对象参数：SysLog
	 * @return  Boolean
	 * @author  LuZhongren
	 * @time    2022年1月27日
	 */
	@PostMapping("/update")
	@ApiOperation(value = "修改", notes = "作者：LuZhongren")
	public AjaxResult<SysLog> update(SysLog entity){
		if (null!=entity) {
			boolean rsg = sysLogService.updateEx(entity) >0? true:false;
			if (rsg) {
				  return AjaxResult.success(MessageUtils.message("update.success"));
			  }else {
				  return AjaxResult.failed(MessageUtils.message("update.fail"));
			  }
		}else {
			return AjaxResult.failed(MessageUtils.message("update.not.exist"));
		}
	}
	
	
}